<template>
  <li>
    <label v-if="!todo.operated">
      <input type="checkbox" :checked="todo.isDone" @click="handleCheck(todo.id)"/>
      <span class="title">{{todo.title}}</span>
      <input type="text" class="date" v-model="dateBegin" :onblur="changeItem(todo.id)" disabled/>
      <input type="text" class="date" v-model="dateEnd" :onblur="changeItem(todo.id)"/>
      <!-- <span class="date">{{todo.dateBegin}}</span>
      <span class="date" >{{todo.dateEnd}}</span> -->
      
    </label>
    <button  v-if="!todo.operated" class="btn btn-danger" @click="deleteItem(todo.id)">删除</button>
  </li>
</template>

<script>
import myDatepicker from 'vue-datepicker/vue-datepicker-es6.vue';
export default {
  name: 'TodoItem',
  component:{
    'date-picker': myDatepicker
  },
  data(){
    return{
      isDone:this.todo.isDone,
      dateBegin:this.todo.date_begin,
      dateEnd:this.todo.date_end
    }
  },
  props: ["todo","delTodo","checkTodo","modifyTodo"],
  methods:{
    handleCheck(id){
      this.isDone = 1-this.isDone;
      this.modifyTodo(id,this.isDone, this.dateEnd);
    },
    deleteItem(id){
      if(confirm("确认删除"))
        this.delTodo(id);
    },
    changeItem(id){
      this.modifyTodo(id,this.isDone, this.dateEnd);
    }

  }
}
</script>
<style scoped>
li{
  list-style: none;
  height: 36px;
  line-height: 36px;
  padding: 0 5px;
  border-bottom: 1px solid #ddd;
}

li label {
  float:left;
  cursor: pointer;
}

li label li input{
  vertical-align: middle;
  margin-right: 6px;
  position: relative;
  top: -1px;
}

li button{
  float: right;
  margin-top: 3px;
  margin-left: 5px;
}

li:before{
  content: initial;
}

li:last-child{
  border-bottom: none;
}

li:hover{
  background-color: #ddd;
}

span,
input{
  display: inline-block; 
  text-align: left;
  margin-left: 10px;
}


.title{
  width: 150px;
  text-align: center;
}

.date{
  width: 140px;
  text-align: center;
}

.date:hover{
  background-color: #ddd;
}

</style>